package com.calsoft.Hops_Mobile_Tablet;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TextView;
import com.calsoft.Hops_Mobile_Tablet.base.CardUI;
import com.calsoft.Hops_Mobile_Tablet.card_ui_fragment.FlightCardUIFragment;
import com.calsoft.Hops_Mobile_Tablet.card_ui_fragment.HotelCardUIFragment;
import com.calsoft.Hops_Mobile_Tablet.card_ui_fragment.ServiceCardUIFragment;
import com.calsoft.Hops_Mobile_Tablet.dummy.StaticData;


/*
 * User: Minh Diep
 * Date: 6/27/13
 * Time: 6:14 PM
 */

public class CardUIDisplayActivity extends FragmentActivity {

    private int typeCard = 0;
    private String itemId = "";
    private String dateCard = "";
    private int startTimeCard = 0;
    private int endTimeCard = 0;
    private Fragment fragment;
    public static final String CARD_UI_ITEM_ID = "com.calsoft.hops.mobile.card.ui.display.activity.item.id";
    public static final String CARD_UI_DATE = "com.calsoft.hops.mobile.card.ui.display.activity.date";
    public static final String CARD_UI_START_TIME = "com.calsoft.hops.mobile.card.ui.display.activity.start.time";
    public static final String CARD_UI_END_TIME = "com.calsoft.hops.mobile.card.ui.display.activity.end.time";

    private TextView nameTextView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_card_ui_display);

        FragmentManager fragmentManager = getSupportFragmentManager();

        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            typeCard = extras.getInt(CardUI.CARD_DISPLAY_TYPE);
            itemId = extras.getString(CardUI.CARD_ITEM_ID, "");
            dateCard = extras.getString(CardUI.CARD_ITEM_DATE, "");
            startTimeCard = extras.getInt(CardUI.CARD_ITEM_START_TIME, 0);
            endTimeCard = extras.getInt(CardUI.CARD_ITEM_END_TIME, 0);
        }

        Bundle bundle = new Bundle();
        bundle.putString(CARD_UI_ITEM_ID, itemId);
        bundle.putString(CARD_UI_DATE, dateCard);
        bundle.putInt(CARD_UI_START_TIME, startTimeCard);
        bundle.putInt(CARD_UI_END_TIME, endTimeCard);

        switch(typeCard){
            case CardUI.TYPE_ADD_SERVICE:
                fragment = new OpToursFragment();
                break;
            case CardUI.TYPE_SERVICE:
                fragment = new ServiceCardUIFragment();
                break;
            case CardUI.TYPE_HOTEL:
                fragment = new HotelCardUIFragment();
                break;
            case CardUI.TYPE_FLIGHT:
                fragment = new FlightCardUIFragment();
                break;
        }
        fragment.setArguments(bundle);
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        if (typeCard == CardUI.TYPE_ADD_SERVICE)
            inflater.inflate(R.menu.op_tours, menu);
        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action buttons
        switch(item.getItemId()) {
            case R.id.action_category_filter:
                OpToursFragment fragment = (OpToursFragment) getSupportFragmentManager().findFragmentById(R.id.content_frame);
                fragment.showCategoryFilterDialog();
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }
}